const koa = require('koa');
const Mysql = require('mysql-pro');
const router = require('koa-router');

const db = new Mysql({
    mysql: {
        host: 'localhost',
        port: 3306,
        user: 'root',
        password: 'root',
        database: '20180412'
    }
});

let server = new koa();
server.listen(8080);

let r1 = router();
server.use(r1.routes());

r1.get('/user', async () => {
    await db.startTransaction();
    let data = await db.executeTransaction("SELECT * FROM user_table");
    await db.stopTransaction();
    console.log(data);
})